#!/usr/bin/python
###############################################################################
#Programmers:                                                                 #
#             Danil Dotsenko, dd@accentsolution.com                           #
#Date: 07/11/2006                                                             #
#Filename: elements.py                                                        #
#Version: 0.1                                                                 #
#                                                                             #
#                                                                             #
#       Copyleft 2006 Danil Dotsenko                                          #
#                                                                             #
#    This program is free software; you can redistribute it and/or modify     #
#    it under the terms of the GNU General Public License as published by     #
#    the Free Software Foundation; either version 2 of the License, or        #
#    (at your option) any later version.                                      #
#                                                                             #
#    This program is distributed in the hope that it will be useful,          #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
#    GNU General Public License for more details.                             #
#                                                                             #
#    You should have received a copy of the GNU General Public License        #
#    along with this program; if not, write to the Free Software              #
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA #
#                                                                             #
###############################################################################

'''
Notes:
- This is a centralized location for functions and methods
  populating the calendar "canvas".
- There are not rendering-engine-specific functions here.
  Since these are only off-screen manupulations,
  we are changing the "canvas / offscreen buffer" vars only.
  Later, actual rendering engine will go through each of
  these and move / draw based on these settings.
'''

class RainlendarOptions:
	'''This dictionary type var is used for matching of Rainlendar
	ini keywords to the methods / properties listed bellow'''
	def __init__(self):
		self.options = {
			'Enable':None,
			'X':None,
			'Y':None,
			'H':None,
			'W':None,
			'Align':None,
			'Rasterizer':None,
			'Font':None,
			'FontColor':None,
			'BitmapName':None,
			'NumOfComponents':None,
			'Separation':None,
			'Layout':None,
			'Names':None
			} #used for textual month and weekday names. String with / separators.
		self.activeElement = {
			'type':None, # (Button, Image, Time)
			'Enable':None,
			'X':None,
			'Y':None,
			'BitmapName':None, # dont forget to spit into 3 parts
			'Command':None,
			'Window':None, # (0-2 main, todo, msgbox, events, , tooltip)
			'Repeat':None, # (0-3 once, all cals, curr month, viewed month)
			'IncludeSize':None, # included into calculation of the size of calendar.)
			'Misc':None
			} # time = format, locale

class canvasClass:
	'''If dayClass is the lowest of all classes, this is a
	fraction of that low. This refers to the layers from which
	each individual day is composed. It includes day number
	images, event and today indicators, etc.
	Each of these layers is assigned one instance of this class.'''
	def __init__(self):
		# self.fileName = None
		self.show = True
		self.imgPtr = None # note, this may be a pointer to a img, as well as text object.
		self.x = 0 # these are relative to day's cell coordinates.
		self.y = 0 # these are relative to day's cell coordinates.
		self.w = 1
		self.h = 1
		self.allignX = 0
		self.allignY = 0
		self.img2Ptr = None # used for 10-part day sources, where we have to build day numbers out of 2 parts.
		self.img2xshift = 0 # shift against the .x in pixels
		self.img2x = self.x+self.img2xshift

class layerClass:
	'''If dayClass is the lowest of all classes, this is a
	fraction of that low. This refers to the layers from which
	each individual day is composed. It includes day number
	images, event and today indicators, etc.
	Each of these layers is assigned one instance of this class.'''
	def __init__(self):
		# self.fileName = None
		self.show = True
		self.imgPtr = None # note, this may be a pointer to a img, as well as text object.
		self.x = 0 # these are relative to day's cell coordinates.
		self.y = 0 # these are relative to day's cell coordinates.
		self.w = 1
		self.h = 1
		self.allignX = 0
		self.allignY = 0
		self.img2Ptr = None # used for 10-part day sources, where we have to build day numbers out of 2 parts.
		self.img2xshift = 0 # shift against the .x in pixels
		self.img2x = self.x+self.img2xshift

	def hide(self, state=True):
		'''hide([False]) Hides the group from view. Can also use hide(False) which shows the group.'''
		# I really should put the hiding function in here o save the cycles, but in order to keep this engine-abnostic will try not to.
		self.show = not state

	def show(self, state=True):
		'''show([False]) Shows the group. Can also use show(False) which fides the group from view.'''
		self.show = state

class dayClass:
	'''This is the lowest level class of Cavas object and
	is assigned to EVERY day of EVERY shown month.
	It contains:
	- pointers to images forming the layers of each day's icon.
	- tooltip textual entry which is attached to the tooltip layer
	- other misc data and functions related to DISPLAY of that particular day.'''
	def __init__(self):
		self.layer = {}
		# layer{} is a dictionary type array. It contains linked pairs of
		# layer name and layer class instances with pointer to image loaded for that particular layer
		# and x and y for that particualr layer RELATIVE to .x and .y of day's cell!
		# EvERY day has it's own layer{} dictionary array.
		# Layer names may include: day, today, event, weekend, tip
		# tip layer - transparent image with a tooltip attached to it.
		# tip layer is always drawn last by rendering engine and sized for the whole day cell.
		self.tip = None # the text of the event headings.
		self.event = None # just a flag
		self.x = 0 # these relate to the general day's cell location relative month's coordinates.
		self.y = 0 # these relate to the general day's cell location relative month's coordinates.
		self.allignX = 0
		self.allignY = 0
		#self.h
		#self.w # h and w are there for POTENTIAL use. May be usefull for magnification.
		self.show = True

	def moveto(self, x, y):
		'''moveto(x,y) Since the day cell may be a multilayer composite, and is relative to month view
		changing the coordinates internally is better, and results in cleaner main code.
		Note we are only changing the coordinates, not actually moving the moving the image.'''
		# I should put the moving function in here, but in order to keep this engine-abnostic will keep this simple for now
		self.x = x
		self.y = y

	def moveby(self, x, y):
		self.x = self.x + x
		self.y = self.y + y

	def hide(self, state=True):
		'''hide([False]) Hides the whole day group from view.
		Can also use hide(False) which shows the group.'''
		self.show = not state

	def show(self, state=True):
		'''
		show([False]) Shows the whole day group.
		Can also use show(False) which fides the group from view.
		Usefull for days like 29,30,31,32, that don't exist in some month.
		'''
		self.show = state

class monthClass:
	'''
	This class is designed to hold settings for a particular month
	and all days contained within that month.

	Besides functions, this class contains the follwoing important vars:
		self.show = True
		self.x = 0 # relative to canvas 0,0
		self.y = 0 # relative to canvas 0,0
		self.day = [] # Slot 0 is reserved for misc use.
		     The rest .day[n] entries refer to the actual days
		     with n - the day's number and contain dayClass instances
		self.daysShown = 0
		self.weekdaystart = 0 # month starts with this weekday.
		self.layout = 2 # (horizontal, vertical, standard)
		self.allignX = 0
		self.allignY = 0

	note. This is not about month's name only. This class hold all things.
	'''
	def __init__(self):
		self.show = True
		self.x = 0 # relative to canvas 0,0
		self.y = 0 # relative to canvas 0,0
		self.day = [] # Slot 0 is reserved for misc use. The rest .day[n] entries refer to the actual days with n - the day's number and contain dayClass instances
		self.monthLable = None
		self.daysShown = 0
		self.weekdaystart = 0 # month starts with this weekday.
		self.layout = 2 # (horizontal, vertical, standard)
		self.allignX = 0
		self.allignY = 0

	def hide(self, state=True):
		'''
		hide([False]) Hides the whole day group from view.
		Can also use hide(False) which shows the group.
		'''
		self.show = not state

	def show(self, state=True):
		'''
		show([False]) Shows the whole day group.
		Can also use show(False) which fides the group from view.
		'''
		self.show = state

class canvas:
	'''
	This class is designed to hold settings for the whole claendar canvas.

	Besides functions, this class contains the follwoing important vars:
		self.show = True
		self.w = 0
		self.h = 0 # w,h very important for stretching the background properly
		self.background = {'Name':None,'ImgPtr':None,'Mode':1,'Color':None}
		 # Mode = (0 = Tile 1 = Transparent 2 = Stretch 3 = Solid color)
		self.month = [] # this refers to actual months calendars, not names.
		self.activeElement = {} # buttons, images, time etc.
		self.weekbegins = 0 # 0-6, 0 = monday
		self.daysConf = {'IgnoreToday':0,'IgnoreEvent':0,'Layout':1,'Spacing':0]
		self.calEventsConf = {'IconEnable':True,'EventsText':False,'TextFont':None,'TextFontColor':None}
	'''
	def __init__(self):
		self.show = True
		self.w = 0
		self.h = 0 # w,h very important for stretching the background properly
		self.settings = {'Background':{'fileName':None,'ImgPtr':None,'Mode':1,'Color':None}}
		 # Mode = (0 = Tile 1 = Transparent 2 = Stretch 3 = Solid color)
		self.month = [] # this refers to actual months calendars, not names.
		self.activeElement = {} # buttons, images, time etc.
		self.weekbegins = 0 # 0-6, 0 = monday
		self.daysConfig = {'IgnoreToday':0,'IgnoreEvent':0,'Layout':1,'Spacing':0}
		self.calEventsConfig = {'IconEnable':True,'EventsText':False,'TextFont':None,'TextFontColor':None}

class activeElement:
	def __init__(self):
		self.elementType = None # (Button, Image, Time)
		self.show = True
		self.window = 0 # (0-2 main, todo, msgbox, events, , tooltip)
		self.repeat = 0 # (0-3 once, all cals, curr month, viewed month)
		self.includeSize = True # (includeSize - calculating the size of calendar.)
		self.x = 0 # relative to canvas 0,0
		self.y = 0
		self.bitmapName = None # (3 frames for button)
		self.action = None
		self.misc = None # (time = format, locale)
